package com.zzyl.controller;

import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "护理等级相关接口")
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;


    /**
     * 分页查询护理等级
     * @param name 护理等级名称
     * @param status 护理等级状态
     * @param pageNum 当前页码
     * @param pageSize 显示数据条数
     * @return
     */
    @ApiOperation(value = "护理等级分页查询接口")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "护理等级状态") Integer status,
            @ApiParam(value = "当前页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "显示数据条数") @RequestParam(defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingLevelVo> pageResponse =  nursingLevelService.getByPage(name,status,pageNum,pageSize);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 添加护理等级
     * @param nursingLevelDto 护理等级信息
     * @return
     */
    @ApiOperation(value = "添加护理等级接口")
    @PostMapping("/insert")
    public ResponseResult addLevel(
            @ApiParam(value = "护理等级信息")
            @RequestBody NursingLevelDto nursingLevelDto
    ){
        nursingLevelService.addLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理等级
     * @param id 护理等级id
     * @return
     */
    @ApiOperation(value = "删除护理等级接口")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteLevel(
            @ApiParam(value = "护理等级id")
            @PathVariable Long id
    ){
        nursingLevelService.deleteLevel(id);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理等级信息
     * @param id 护理等级id
     * @return
     */
    @ApiOperation(value = "根据id查询护理等级信息接口")
    @GetMapping("/{id}")
    public ResponseResult getLevelById(
            @ApiParam(value = "护理等级id")
            @PathVariable Long id
    ){
        NursingLevelVo nursingLevelVo = nursingLevelService.getLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 修改护理等级信息
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation(value = "修改护理等级信息接口")
    @PutMapping("/update")
    public ResponseResult updateLevel(
            @ApiParam(value = "修改后护理等级信息")
            @RequestBody NursingLevelDto nursingLevelDto
    ){
        nursingLevelService.updateLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 查询所有护理等级
     * @return
     */
    @ApiOperation("查询所有护理等级接口")
    @GetMapping("/listAll")
    public ResponseResult getAllLevel(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.getAllLevel();
        return ResponseResult.success(nursingLevelVos);
    }


    /**
     * 修改护理等级状态
     * @param id 护理等级id
     * @param status 护理等级状态
     * @return
     */
    @ApiOperation(value="修改护理等级状态接口")
    @PutMapping("{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理等级id")
            @PathVariable Long id,
            @ApiParam(value = "护理等级状态")
            @PathVariable Integer status
    ){
        nursingLevelService.updateStatus(id,status);
        return ResponseResult.success();
    }

}
